<template>
<div id="SupList" class="page-blank">
  <van-nav-bar title="特殊用户" left-arrow @click-left="goBack()"/>
  <van-search v-model="searchValue" placeholder="请输入用户名称" show-action shape="round">        
    <div slot="action" @click="onSearch" class="ft-blue">搜索</div>
  </van-search>
  <div class="flex-body">    
    <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="getList">
      <div class="data-box"  v-for="(v,i) in list" :key="i">
        <div class="data-title">用户名称：{{ v.nick }}({{ v.userId }})
          <span class="right" @click="modify(v)" v-if="roleType !== 3">修改</span>
        </div>
        <div class="data-main">
          <div>
            <span class="label">免费类别：</span>
            <span class="value">{{ freeCategoryColumns[ v.freeCategory ] }}</span></div>
          <div v-for="(value,index) in v.freeCategory === 1 ? [] : v.specialUserByShopModelList" :key="index">
            <span class="label">门店{{ index + 1 }}：</span>
            <span class="value">{{ value.shopName }}</span>
          </div>
          <div>
            <span class="label">充电宝每天免费时长：</span>
            <span class="value">{{ v.specialPlaTime }}小时</span>
          </div>
        </div>
      </div>
    </van-list>
  </div>
</div>
</template>

<script lang="ts">
import { Vue, Component } from 'vue-property-decorator';
import axios from '@/utils/request';

@Component
export default class SupList extends Vue {

  roleType: any = this.$store.state.userInfo.roleType
  freeCategoryColumns: any = ['指定门店使用免费','所有门店使用免费']
  list: any = []
  page: any = 1
  loading: any = false
  finished: any = false
  searchValue: any = ''

  onSearch() {
    this.page = 1
    this.list = [];
    this.loading = true;
    this.finished = false;
    this.getList()
  }
  getList() {
    let query: any = { page: this.page, size: 10 };
    if(this.searchValue) query.userName = this.searchValue;
    axios.get('/api/SpecialUserController/getSpecialUserList', query).then((res: any) => {      
      let list = res.list||[];
      this.loading = false;
      this.list.push( ...list );
      this.page = this.page + 1;
      if(res.isLastPage) this.finished=true;
    }).catch(() => {
      this.loading = false;
      this.finished = true;
    });
  }
  modify(people: any) {
    this.$router.push({ name: 'AddSup', query: { type: 'modify' }, params: people });
  }

  goBack() {
    this.$router.go(-1);
  }

  mounted() {
  }
  
};
</script>

<style lang="scss">
#SupList {  
  .data-box {
    line-height: 26px;
    background: #fff;
    box-shadow: 1px 1px 2px 1px #dedede;
    border-radius: 3px;
    padding: 0 10px;
    font-size: 0.24rem;
    box-sizing: border-box;
    width: 6.7rem;
    margin: 0.1rem auto;
  }
  .data-box .data-title {
    line-height: 30px;
    border-bottom: 1px solid #dedede;
  }
  .data-box .data-title .right {
    float: right;
    color: #0086d1;
    cursor: pointer;
  }
  .data-box .data-main {
    padding: 5px 0;
  }
  .data-box .data-main .label {
    color: #0086d1;
  }
}
</style>

